package com.corpgovernment.common.deepmd5;


import java.security.MessageDigest;

public class MD5 {
    private static final char[] HEX_DIGITS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    public MD5() {
    }

    /** @deprecated */
    @Deprecated
    public String toDigest(String src) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(src.getBytes());
            return getFormattedText(messageDigest.digest());
        } catch (Exception var3) {
            throw new RuntimeException(var3);
        }
    }

    public static String toDigestUTF8(String src) {
        return (new MD5()).toDigest(src, "UTF8");
    }

    public String toDigest(String src, String charset) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(src.getBytes(charset));
            return getFormattedText(messageDigest.digest());
        } catch (Exception var4) {
            throw new RuntimeException(var4);
        }
    }

    private static String getFormattedText(byte[] bytes) {
        int len = bytes.length;
        StringBuilder buf = new StringBuilder(len * 2);

        for(int j = 0; j < len; ++j) {
            buf.append(HEX_DIGITS[bytes[j] >> 4 & 15]);
            buf.append(HEX_DIGITS[bytes[j] & 15]);
        }

        return buf.toString();
    }
}

